SUMMARY = "The canonical example of init scripts"
SECTION = "base"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://${WORKDIR}/COPYRIGHT;md5=349c872e0066155e1818b786938876a4"

SRC_URI = "file://skeleton \
	   file://skeleton.service.in \
	   file://skeleton_test.c \
	   file://COPYRIGHT \
	   "

inherit update-rc.d systemd
INITSCRIPT_NAME = "skeleton"
INITSCRIPT_PARAMS = "defaults 99"
#INITSCRIPT_PARAMS = "start 99 2 3 4 5 . stop 09 0 5 6 1 ."

SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE_${PN} = "skeleton.service"
SYSTEMD_AUTO_ENABLE = "enable"

do_compile () {
	${CC} ${CFLAGS} ${LDFLAGS} ${WORKDIR}/skeleton_test.c -o ${WORKDIR}/skeleton-test
}

do_install () {
	if ${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'true', 'false', d)}; then
		install -d ${D}${sysconfdir}/init.d
		cat ${WORKDIR}/skeleton | \
		  sed -e 's,/etc,${sysconfdir},g' \
			  -e 's,/usr/sbin,${sbindir},g' \
			  -e 's,/var,${localstatedir},g' \
			  -e 's,/usr/bin,${bindir},g' \
			  -e 's,/usr,${prefix},g' > ${D}${sysconfdir}/init.d/skeleton
		chmod a+x ${D}${sysconfdir}/init.d/skeleton
	fi

	if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
		install -D -m 0644 ${WORKDIR}/skeleton.service.in ${D}${systemd_unitdir}/system/skeleton.service
	fi

	install -d ${D}${sbindir}
	install -m 0755 ${WORKDIR}/skeleton-test ${D}${sbindir}/
}

RDEPENDS_${PN} = "initscripts"

CONFFILES_${PN} += "${sysconfdir}/init.d/skeleton"
FILES_${PN} += "${systemd_unitdir}"
FILES_${PN} += "${sbindir}"

PACKAGE_STRIP = "no"
INSANE_SKIP_${PN} := "installed-vs-shipped"
